

<?php

class Chart extends Controller {

    function Chart() {
        parent::Controller();
        $this->load->model(array('mod_chart'));
    }

    //========================function for load page master====================//

    function index() {
        if($this->check_session()){
        $this->load->view('master');
        }else{
            redirect('admin/');
            exit();
        }
    }

    //========================this is function for loading page master===========//

    function manager() {
		if($this->check_session()){
			//$data['select_data'] = $this->mod_user->selectuser();
			$data['title'] = 'Yearly Chart';
			//public
			//get oldest date
			$data1=$this->mod_chart->getOldestYear();
			foreach($data1->result() as $row){
				$data['oldestYear']=$row->year;
				$data['numYear']=date('Y')-$row->year+1;
				for($i=0;$i<$data['numYear'];$i++){
					$data['results'.(5-$i)]=$this->mod_chart->getPublicClass(date('Y')-$i);
					if($i==4) break;
				}
			}
			//private
			$data2=$this->mod_chart->getOldestYearPr();
			foreach($data2->result() as $row){
				$data['oldestYearPr']=$row->year;
				$data['numYearPr']=date('Y')-$row->year+1;
				for($i=0;$i<$data['numYearPr'];$i++){
					$data['resultsPr'.(5-$i)]=$this->mod_chart->getPrivateClass(date('Y')-$i);
					if($i==4) break;
				}
			}
			//product
			//private
			$data2=$this->mod_chart->getOldestYearPro();
			foreach($data2->result() as $row){
				$data['oldestYear2']=$row->year;
				$data['numYear2']=date('Y')-$row->year+1;
				for($i=0;$i<$data['numYear2'];$i++){
					$data['results2'.(5-$i)]=$this->mod_chart->getProduct(date('Y')-$i);
					if($i==4) break;
				}
			}
			$this->load->view('master', $data);
        }else{
            redirect('admin/');
            exit();
        }
    }

    

//===========================function  is the end of  used for delete data from tbl_user========================//
    
     //========this is function for using checking session=============
    
     public function check_session() {
        if ($this->session->userdata('use_username')) {
            return true;
        } else {
            return false;
        }
    }
}